import {createFieldWrapper} from '@/utils/FormDesignUtils';
import {isEmpty} from "@/utils";
import { message } from 'ant-design-vue';

export default class AbstractField {
  getFieldComponentTitle() {
  }

  getFieldComponentName() {
  }

  getDefaultConfig() {
    return new Promise((resolve, reject) => {
    });
  }

  setFieldTitle(el, fieldConfig) {

  }

  createField() {
    return new Promise((resolve, reject) => {
      this.getDefaultConfig().then(config => {
        this.createFieldElement(config).then(el => {
          el = createFieldWrapper(el);
          resolve({el, config});
        }).catch(reject);
      }).catch(reject);
    });
  }

  checkField(field) {
    if (isEmpty(field.label)) {
      message.error('字段标题不能为空')
      return false
    }
    // if (isEmpty(field.fieldName)) {
    //   message.error('字段名称不能为空')
    //   return false
    // }
    if (isEmpty(field.length)) {
      message.error('字段长度不能为空')
      return false
    }
    return true
  }

  createFieldElement(config) {
    return new Promise((resolve, reject) => {
    });
  }

  isCustomComponent() {
    return false;
  }
}
